#include <iostream>
#include <easylog.h>

using namespace easylog;

const std::string logpath = "logs/";
const std::string logfile = "log_%d{%F-%H_%M_%S}.log";
const int gaptime = 1;

volatile bool stop = false;

void sig_hdr(int signo)
{
    std::cout << "log process was being killed cause signal " << signo << std::endl;
    stop = true;
}

void loop()
{
    logger_builder::ptr llb = std::make_shared<local_logger_builder>();

    llb->build_logger_type(logger_builder::sync);
    llb->build_logger_name("sync");
    llb->build_limit_level(level::debug);
    llb->build_sinker<roll_over_time>(logpath + logfile, size_enum::m500MB, gaptime, size_enum::m500MB);

    logger::ptr lgr = llb->build();

    int i = 0;

    while (true)
    {
        lgr->info("{}:{}", "info log test", i++);

        if (stop)
            break;

        std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }
}

int main()
{
    for (int i = 0; i < 31; i++)
        signal(i, sig_hdr);

    loop();

    return 0;
}
